/*
 * MscsView.java
 */

package mscs.client.view;

import mscs.client.goods.view.AddGoodsPanel;
import mscs.client.goods.view.GeneralPanel;
import mscs.client.goods.view.ManageGoodsPanel;
import mscs.client.goods.view.NetTransPanel;
import mscs.client.goods.view.OperationPanel;
import mscs.client.goods.view.OutGoodsPanel;
import mscs.client.member.view.AddMemberPanel;
import mscs.client.member.view.MemberChoosePanel;
import mscs.client.member.view.SearchMemberPanel;
import mscs.data.pojo.Person;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;

/**
 * The application's main frame.
 */
public class MscsView extends FrameView {

    public MscsView(SingleFrameApplication app, Person person) {
        super(app);
        this.person = person;
        initComponents();
        setEnvironment();
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();

        mainPanel.setName("mainPanel"); // NOI18N

        jSplitPane1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jSplitPane1.setDividerLocation(120);
        jSplitPane1.setEnabled(false);
        jSplitPane1.setName("jSplitPane1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("商品管理");
        javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("商品入库");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("商品出库");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("查看商品");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("操作历史");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("会员管理");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("查看会员");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("增加会员");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("礼品赠送");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("数据同步");
        treeNode1.add(treeNode2);
        jTree1.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        jTree1.setName("jTree1"); // NOI18N
        jTree1.setRootVisible(false);
        jTree1.setToggleClickCount(1);
        jTree1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTree1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTree1);

        jSplitPane1.setLeftComponent(jScrollPane1);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 701, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );

        setComponent(mainPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void jTree1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTree1MouseClicked
        if(jTree1.getSelectionPath() != null) {
        String option = jTree1.getSelectionPath().getLastPathComponent().toString();
        if("商品管理".equals(option)){
            jSplitPane1.setRightComponent(new GeneralPanel());
        } else if("商品入库".equals(option)) {
            addGoodsPanel.refreshTable();
            jSplitPane1.setRightComponent(addGoodsPanel);
        }
        else if("商品出库".equals(option)) {
            outGoodsPanel.refreshTable();
            jSplitPane1.setRightComponent(outGoodsPanel);
        }
        else if("查看商品".equals(option)) {
            manageGoodsPanel.refreshTable();
            jSplitPane1.setRightComponent(manageGoodsPanel);
        }
        else if("操作历史".equals(option)) {
            operationPanel.refreshTable();
            jSplitPane1.setRightComponent(operationPanel);
        }
        else if("会员管理".equals(option)) {
            jSplitPane1.setRightComponent(new GeneralPanel());
        }else if("增加会员".equals(option)){
            jSplitPane1.setRightComponent(addMemberPanel);
        }
        else if("查看会员".equals(option)) {
            jSplitPane1.setRightComponent(searchMemberPanel);
        }else if("礼品赠送".equals(option)){
            this.memberChoosePanel.refreshTable();
            jSplitPane1.setRightComponent(this.memberChoosePanel);
        }
        else if("数据同步".equals(option)) {
            jSplitPane1.setRightComponent(netTransPanel);
        }
        else {}
        jSplitPane1.setDividerLocation(120);
        }
    }//GEN-LAST:event_jTree1MouseClicked
    
    private void setEnvironment() {
        operationPanel = new OperationPanel(this);
        addGoodsPanel = new AddGoodsPanel(this);
        outGoodsPanel = new OutGoodsPanel(this);
        manageGoodsPanel = new ManageGoodsPanel(this);
        addMemberPanel = new AddMemberPanel(this);
        searchMemberPanel = new SearchMemberPanel(this);
        memberChoosePanel = new MemberChoosePanel(this);
        netTransPanel = new NetTransPanel();
        jSplitPane1.setRightComponent(new GeneralPanel());
        jSplitPane1.setDividerLocation(120);
    }
    public Person getPerson() {
        return person;
    }
    OperationPanel operationPanel;
    AddGoodsPanel addGoodsPanel;
    OutGoodsPanel outGoodsPanel;
    ManageGoodsPanel manageGoodsPanel;
    AddMemberPanel addMemberPanel;
    SearchMemberPanel searchMemberPanel;
    MemberChoosePanel memberChoosePanel;
    NetTransPanel netTransPanel;
    Person person;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTree jTree1;
    private javax.swing.JPanel mainPanel;
    // End of variables declaration//GEN-END:variables

}
